package com.tadpole.music.view.activity.me;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;


import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tadpole.music.R;

import com.tadpole.music.adapter.me.AnswerStatisticsV2Adapter;


import com.tadpole.music.adapter.me.AnswerStatisticsV3Adapter;
import com.tadpole.music.bean.me.MoNiErrorBean;
import com.tadpole.music.holder.me.AnswerStatisticsV2ViewHolder;
import com.tadpole.music.iView.me.MoNiListIView;
import com.tadpole.music.presenter.me.MoNiListPresenter;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.view.activity.base.BaseActivity;


import com.tadpole.music.view.widget.NiceImageView;

import java.util.List;

/**
 * 答题统计
 * Created By 孙岩
 * on 2020/12/25
 */
public class AnswerStatisticsV2Activity extends BaseActivity implements MoNiListIView {
    //回退
    private View view_back_icon;
    //学生头像
    private NiceImageView ivImage;
    //学生姓名
    private TextView tvName;

    private RecyclerView rv;

    private AnswerStatisticsV2Adapter answerStatisticsV2Adapter;
    private AnswerStatisticsV3Adapter answerStatisticsV3Adapter;
    //学生id
    private int student_id;
    //学生头像
    private String student_avatar;
    //学生昵称
    private String student_nickname;

    private MoNiListPresenter moNiListPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_answer_statistice_v2);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        student_id = getIntent().getIntExtra("student_id",0);
        student_avatar = getIntent().getStringExtra("student_avatar");
        student_nickname = getIntent().getStringExtra("student_nickname");

        initViews();
        initListeners();

        moNiListPresenter = new MoNiListPresenter();
        moNiListPresenter.attachView(this);
        moNiListPresenter.getMoNiList(student_id);
    }

    //初始化控件
    private void initViews(){
        view_back_icon = findViewById(R.id.view_back_icon);
        ivImage = findViewById(R.id.ivImage);
        tvName = findViewById(R.id.tvName);
        rv = findViewById(R.id.rv);

        tvName.setText(student_nickname);

        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.mipmap.app_icon)
                .error(R.mipmap.app_icon)
                .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(this).load(student_avatar).apply(requestOptions).into(ivImage);

    }

    //初始化监听器
    private void initListeners(){
        view_back_icon.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                AnswerStatisticsV2Activity.this.finish();
            }
        });
    }

    @Override
    public void showMoNiList(List<MoNiErrorBean.DataBean> list) {

        if(list==null||list.size()==0){

        }else{

//            LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
//            rv.setLayoutManager(layoutManager);
//            //创建适配器
//            answerStatisticsV3Adapter = new AnswerStatisticsV3Adapter(this,R.layout.item_big,list,getSupportFragmentManager(),student_id,student_avatar,student_nickname);
//            answerStatisticsV3Adapter.setHasStableIds(true);
//            //给RecyclerView设置适配器
//            rv.setAdapter(answerStatisticsV3Adapter);

//            rv.setNestedScrollingEnabled(false);

            LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
            rv.setLayoutManager(layoutManager);
            //创建适配器
            answerStatisticsV2Adapter = new AnswerStatisticsV2Adapter(this,getSupportFragmentManager(),student_id,student_avatar,student_nickname,list);
            answerStatisticsV2Adapter.setHasStableIds(true);
            //给RecyclerView设置适配器
            rv.setAdapter(answerStatisticsV2Adapter);


        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
